using System.Collections;
using Holoville.HOTween;
using Holoville.HOTween.Core;
using I2.Loc;
using UnityEngine;
using UnityEngine.SceneManagement;

public class AchivmentUnlokedPanel : MonoBehaviour
{
	public UILabel nameLabel1;

	public UILabel nameLabel2;

	public UILabel descriptionLabel;

	public UISprite iconSprite;

	public UIPanel panel;

	public RewardUIPanel rewardPanel;

	public Achievement currentAchievement;

	public IEnumerator Init(Achievement achievement, float liveTime)
	{
		AchievementsManager.instanse.achievementUnlokedMessage = true;
		while (MarketControllerUI.instance.MarketActive())
		{
			yield return null;
		}
		currentAchievement = achievement;
		nameLabel1.text = ScriptLocalization.Get("Achivments/" + achievement.achievementNameID + "_Title");
		nameLabel2.text = nameLabel1.text;
		descriptionLabel.text = ScriptLocalization.Get("Achivments/" + achievement.achievementNameID + "_Description");
		iconSprite.spriteName = achievement.achievementIcon;
		rewardPanel.Init(achievement.reward);
		SlideIn();
	}

	private void SlideIn()
	{
		panel.alpha = 0.01f;
		HOTween.Init();
		float y = 200f;
		if (SceneManager.GetActiveScene().name == "Lobby")
		{
			y = 400f;
		}
		HOTween.To(base.transform, 0.75f, new TweenParms().Prop("localPosition", new Vector3(0f, y, 0f), true).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			if (currentAchievement.canGiveReward)
			{
				currentAchievement.GiveReward(rewardPanel.transform.position);
				currentAchievement.SaveRewarded(true);
			}
			CoroutineRunner.Instance.StartCoroutine(SlideOut());
		}));
		HOTween.To(panel, 0.7f, new TweenParms().Prop("alpha", 1));
	}

	private IEnumerator SlideOut()
	{
		yield return new WaitForSeconds(5f);
		float endPosition = -200f;
		if (SceneManager.GetActiveScene().name == "Lobby")
		{
			endPosition = -400f;
		}
		HOTween.To(base.transform, 0.75f, new TweenParms().Prop("localPosition", new Vector3(0f, endPosition, 0f), true).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			SelfDestruct();
		}));
		HOTween.To(panel, 0.7f, new TweenParms().Prop("alpha", 0.01f));
	}

	private void SelfDestruct()
	{
		AchievementsManager.instanse.achievementUnlokedMessage = false;
		AchievementsManager.instanse.TryShowAchievementUnlokedPanel();
	}
}
